# The purpose of this pipeline is to exercise local developer workflow in the consolidated
# runtime repo. In particular, it is supposed to run the root "build" script just like any
# normal developer normally would and monitor regressions w.r.t. this fundamental scenario.

trigger: none

pr:
  branches:
    include:
    - main
    - release/*.*
  paths:
    include:
    - '*'
    - eng/pipelines/global-build.yml
    exclude:
    - '**.md'
    - .devcontainer/*
    - .github/*
    - docs/*
    - eng/pipelines/coreclr/*.*
    - eng/pipelines/libraries/*.*
    - eng/pipelines/installer/*.*
    - PATENTS.TXT
    - THIRD-PARTY-NOTICES.TXT

variables:
  - template: /eng/pipelines/common/variables.yml

extends:
  template:  /eng/pipelines/common/templates/pipeline-with-resources.yml
  parameters:
    stages:
    - ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
      - stage: EvaluatePaths
        displayName: Evaluate Paths
        jobs:
          - template: /eng/pipelines/common/evaluate-default-paths.yml

    - stage: Build
      jobs:

      #
      # Build with Release config and Debug runtimeConfiguration
      #
      - template: /eng/pipelines/common/platform-matrix.yml
        parameters:
          jobTemplate: /eng/pipelines/common/global-build-job.yml
          buildConfig: release
          platforms:
          - windows_x86
          - osx_x64
          - osx_arm64
          jobParameters:
            testGroup: innerloop
            nameSuffix: Runtime_Debug
            buildArgs: -c release -runtimeConfiguration debug
            timeoutInMinutes: 120
            condition:
              or(
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_coreclr.containsChange'], true),
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_non_mono_and_wasm.containsChange'], true),
                eq(variables['isRollingBuild'], true))

      #
      # Build with Release config and runtimeConfiguration with MSBuild generator
      #
      - template: /eng/pipelines/common/platform-matrix.yml
        parameters:
          jobTemplate: /eng/pipelines/common/global-build-job.yml
          buildConfig: release
          platforms:
          - windows_x86
          jobParameters:
            testGroup: innerloop
            nameSuffix: MSBuild_CMake
            buildArgs: -c Release -msbuild
            timeoutInMinutes: 120
            condition:
              or(
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_coreclr.containsChange'], true),
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_non_mono_and_wasm.containsChange'], true),
                eq(variables['isRollingBuild'], true))

      #
      # Build with Debug config and Release runtimeConfiguration
      #
      - template: /eng/pipelines/common/platform-matrix.yml
        parameters:
          jobTemplate: /eng/pipelines/common/global-build-job.yml
          buildConfig: debug
          platforms:
          - linux_x64_dev_innerloop
          jobParameters:
            testGroup: innerloop
            nameSuffix: Runtime_Release
            buildArgs: -c debug -runtimeConfiguration release
            timeoutInMinutes: 120
            condition:
              or(
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_coreclr.containsChange'], true),
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_non_mono_and_wasm.containsChange'], true),
                eq(variables['isRollingBuild'], true))

      #
      # Build with RuntimeFlavor only. This exercise code paths where only RuntimeFlavor is
      # specified. Catches cases where we depend on Configuration also being specified
      #
      - template: /eng/pipelines/common/platform-matrix.yml
        parameters:
          jobTemplate: /eng/pipelines/common/global-build-job.yml
          buildConfig: debug
          platforms:
          - linux_x64_dev_innerloop
          jobParameters:
            testGroup: innerloop
            nameSuffix: RuntimeFlavor_Mono
            buildArgs: /p:RuntimeFlavor=Mono
            timeoutInMinutes: 120
            condition:
              or(
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_non_wasm.containsChange'], true),
                eq(variables['isRollingBuild'], true))

      #
      # Build Mono + Libraries. This exercises the code path where we build libraries without
      # first building CoreCLR
      #
      - template: /eng/pipelines/common/platform-matrix.yml
        parameters:
          jobTemplate: /eng/pipelines/common/global-build-job.yml
          buildConfig: debug
          platforms:
          - windows_x64
          jobParameters:
            testGroup: innerloop
            nameSuffix: Mono_Libraries
            buildArgs: -subset mono+libs /p:RuntimeFlavor=Mono
            timeoutInMinutes: 120
            condition:
              or(
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_non_wasm.containsChange'], true),
                eq(variables['isRollingBuild'], true))

      #
      # Build Libraries AllConfigurations. This exercises the code path where we build libraries for all
      # configurations on a non Windows operating system.
      #
      - template: /eng/pipelines/common/platform-matrix.yml
        parameters:
          jobTemplate: /eng/pipelines/common/global-build-job.yml
          buildConfig: debug
          platforms:
          - linux_x64_dev_innerloop
          jobParameters:
            nameSuffix: Libraries_AllConfigurations
            buildArgs: -subset libs -allconfigurations
            timeoutInMinutes: 120
            condition:
              or(
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_non_mono_and_wasm.containsChange'], true),
                eq(variables['isRollingBuild'], true))

      #
      # SourceBuild Build
      #
      - template: /eng/pipelines/common/platform-matrix.yml
        parameters:
          jobTemplate: /eng/pipelines/common/global-build-job.yml
          buildConfig: Release
          platforms:
          - SourceBuild_linux_x64
          jobParameters:
            nameSuffix: PortableSourceBuild
            timeoutInMinutes: 95
            condition:
                eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_non_mono_and_wasm.containsChange'], true)
